package io.shuttle.mbe.api

import io.shuttle.mbe.api.annotation.ChromeMinVersion
import io.shuttle.mbe.api.types.Value2Function

interface DesktopCapture {
    // Hides desktop media picker dialog shown by chooseDesktopMedia().
     fun cancelChooseDesktopMedia(
        // Id returned by chooseDesktopMedia()
        desktopMediaRequestId: Number
    )

    // Shows desktop media picker UI with the specified set of sources.
    // @return An id that can be passed to cancelChooseDesktopMedia() in case the prompt need to be canceled.
     fun chooseDesktopMedia(
        // Set of sources that should be shown to the user. The sources order in the set decides the tab order in the picker.
        sources: List<DesktopCaptureSourceType>,
        // Optional tab for which the stream is created. If not specified then the resulting stream can be used only by the calling extension. The stream can only be used by frames in the given tab whose security origin matches tab.url. The tab's origin must be a secure origin, e.g. HTTPS.
        targetTab: Tabs.Tab?,
        callback: Value2Function<String, ChooseDesktopMediaCallbackData>,
    ): Number

    data class ChooseDesktopMediaCallbackData(
        // An opaque string that can be passed to getUserMedia() API to generate media stream that corresponds to the source selected by the user. If user didn't select any source (i.e. canceled the prompt) then the callback is called with an empty streamId. The created streamId can be used only once and expires after a few seconds when it is not used.
        var streamId: String,
        // Contains properties that describe the stream.
        @ChromeMinVersion(57)
        var option: StreamOptions
    ) {
        data class StreamOptions(
            // True if "audio" is included in parameter sources, and the end user does not uncheck the "Share audio" checkbox. Otherwise false, and in this case, one should not ask for audio stream through getUserMedia call.
            var canRequestAudioTrack: Boolean
        )
    }

    // Enum used to define set of desktop media sources used in chooseDesktopMedia().
    enum class DesktopCaptureSourceType {
        screen,
        window,
        tab,
        audio,
    }

    @ChromeMinVersion(107)
    enum class SelfCapturePreferenceEnum {
        include,
        exclude
    }

    @ChromeMinVersion(105)
    enum class SystemAudioPreferenceEnum {
        include,
        exclude
    }

    enum class WindowAudioPreferenceEnum {
        system,
        window,
        exclude
    }
}